package com.crmapi.service.impl;

import com.crmapi.mapper.ProductMapper;
import com.crmapi.pojo.PageBean;
import com.crmapi.pojo.Product;
import com.crmapi.service.ProductService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class ProductServiceImpl implements ProductService {

    @Autowired
    ProductMapper productMapper;

    //新增产品
    @Override
    public int save(Product product) {
        return productMapper.save(product);
    }

    //批量删除
    @Override
    public int delete(List<String> ids) {
        return productMapper.delete(ids);
    }

    //更新产品
    @Override
    public int update(Product product) {
        return productMapper.update(product);
    }

    //条件查询
    @Override
    public PageBean queryList(Integer page, Integer pageSize, String code, String name, Double price, Integer num, Integer status, String note) {
        PageHelper.startPage(page,pageSize);
        List<Product> list= productMapper.queryList(code,name,price,num,status,note);
        PageInfo pageInfo = new PageInfo<>(list);
        PageBean pageBean = new PageBean(pageInfo.getTotal(),list);
        return pageBean;
    }

    @Override
    public List<Product> queryAll() {
        return productMapper.queryAll();
    }
}
